package com.fzj.example.jdk18;

import java.util.*;
import java.util.function.Consumer;

/**
 * ClassName: LambdaDemo
 * date: 2019/11/11 13:47
 * Description: TODO
 *
 * @author fanzj@bonree.com
 * @since JDK 1.8
 */
public class LambdaDemo {
    public static void main(String[] args) {
        //无参无返回
        Runnable runnable=()->System.out.println("fdaf");
        //有参无返回
        Consumer<String> consumer=(x)->System.out.println(x);
        consumer.accept("test");
        //有参有返回
        Comparator<Integer> comparator=(x,y)->{
            return Integer.compare(x,y);
        };
        //Comparator<Integer> comparator=(x,y)->return Integer.compare(x,y);
        Integer[] arr=new Integer[]{1,32,2323,3,2};
        List<Integer> setCon=new ArrayList<>(Arrays.asList(arr));
        setCon.forEach(x->System.out.println(x));
        setCon.sort(comparator);
        setCon.forEach(x->System.out.println(x));
        //调用模式
        Integer sum=add(100,(x)->x+x);
        Integer sum2=add(100,200,(x,y)->x+y);

    }

    public static Integer add(Integer x,Sum sum){
        return sum.sum(x);
    }
    public static Integer add(Integer x,Integer y,Sum2 sum){
        sum.printMsg(x,y);
        return sum.sum(x,y);
    }
}
